home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
clean
/
sun3.lha
/
Sun3
/
seqdemos
/
e.icl
next >
Wrap
Text File
|
1992-08-07
|
1KB
|
69 lines
MODULE e;
<<
Approximation of the number e.
Result: A list containing the first NrDigits digits of e = [2,7,1,8,2,8,1,8,2,8,...].
>>
IMPORT deltaI;
MACRO
NrDigits -> 200; == The number of digits of the approximation of e
RULE
==
== Some miscellaneous functions on lists:
==
:: Hd [x] -> x;
Hd [hd|tl] -> hd;
:: Tl [x] -> [x];
Tl [hd|tl] -> tl;
== Take takes the first n elements of a list
:: Take INT [x] -> [x];
Take 0 l -> [];
Take n [h|t] -> [h | Take (-- n) t];
Take n [] -> [];
==
== Approximating e:
==
:: Approx_e -> [INT];
Approx_e -> [2 | Expan ones],
ones: [1 | ones];
<< Expan expects an infinite list of ones and returns an infinite
list containing the digits of the fraction of e ([7,1,8,2,8,...]).
>>
:: Expan [INT] -> [INT];
Expan f -> [Hd ten | Expan (Tl ten)],
ten : Ten 2 f;
:: Ten INT [INT] -> [INT];
Ten c [p|q] -> [/ k c, + (% k c) a1 | b1] , IF Safe k:(* 10 p) c
-> [/ (+ k a1) c, % (+ k a1) c | b1],
a1: Hd ten,
b1: Tl ten,
ten: Ten (++ c) q;
:: Safe INT INT -> BOOL;
Safe k c -> = (/ k c) (/ (+ k 9) c);
<<
The Start rule returns the first NrDigits elements of the
list of digits returned by the function
'Approx_e' by means of the function Take.
>>
:: Start -> [INT];
Start -> Take NrDigits Approx_e;